
package SSF.OS.TCP;

import SSF.OS.*;

/**
 * A simplified TCP header.
 */
public class TCP_Header extends SSF.OS.ProtocolMessage 
{	
  /**
   * destination port number 
   */
  public int DEST_port;
  /**
   * source port number
   */
  public int SOURCE_port;
  /**
   * sequence number of the first data byte in segment
   */
  public long SEQno ;
  /**
   * Acknowledgment number (next sequence number expected)
   */
  public long ACKno ;
  /**
   * Advertised receive window size
   */
  public int AdvertisedWnd;
  /**
   * Control flags of TCP header
   */
  public byte flags;

  /* TCP header flags */
  public static byte FIN = 1;
  public static byte SYN = 2;
  public static byte RST = 4;
  public static byte PSH = 8;
  public static byte ACK = 16;
  public static byte URG = 32;

  /**
   * initialize a TCP_Header object
   * @param dest_port destination port number
   * @param source_port source port number
   * @param seqno sequence number of the first data byte in segment
   * @param ackno acknowledgment number of the ACK packet
   * @param advertised advertised receiver window size
   * @param flag control flag used to indicate packet type
   */
  public TCP_Header (int  source_port,int dest_port, long seqno, long ackno,
		      int advertised, byte flag)
  {
    DEST_port = dest_port;
    SOURCE_port = source_port;
    SEQno = seqno;
    ACKno = ackno;
    AdvertisedWnd = advertised;
    flags = flag;
  }

  public TCP_Header()
  {
    DEST_port = 0;
    SOURCE_port = 0;
    SEQno = 0;
    ACKno = 0;
    AdvertisedWnd = 0;
    flags = 0;
  }
  /** 
   * copy constructor of TCP_Header
   * @param th TCP_Header object to be copied
   */
  public TCP_Header(TCP_Header th)
  {
    DEST_port = th.DEST_port;
    SOURCE_port = th.SOURCE_port;
    SEQno = th.SEQno;
    ACKno = th.ACKno;
    AdvertisedWnd = th.AdvertisedWnd;
    flags = th.flags;

  }
  /**
   * return the number of bytes nominally used by this TCP header
   */
  public int bytecount(){
    return 20;
  }

  /**
   * Return the SSF.OS.TCP version number for this header
   */
  public String version(){
    return new String("V0.8");
  }
}




